/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author user0
 */
@Entity
@Table(name = "PRODUCT")
@XmlRootElement
@NamedQueries({
	@NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"),
	@NamedQuery(name = "Product.findByProductId", query = "SELECT p FROM Product p WHERE p.productId = :productId"),
	@NamedQuery(name = "Product.findByName", query = "SELECT p FROM Product p WHERE p.name = :name"),
	@NamedQuery(name = "Product.findByCode", query = "SELECT p FROM Product p WHERE p.code = :code"),
	@NamedQuery(name = "Product.findByPoints", query = "SELECT p FROM Product p WHERE p.points = :points"),
	@NamedQuery(name = "Product.findByPrice", query = "SELECT p FROM Product p WHERE p.price = :price")})
public class Product implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Basic(optional = false)
        @Column(name = "PRODUCT_ID")
	private Integer productId;
	@Basic(optional = false)
        @Column(name = "NAME")
	private String name;
	@Basic(optional = false)
        @Column(name = "CODE")
	private String code;
	@Basic(optional = false)
        @Column(name = "POINTS")
	private int points;
	@Basic(optional = false)
        @Column(name = "PRICE")
	private float price;
	@JoinTable(name = "STORE_PRODUCT", joinColumns = {
        	@JoinColumn(name = "PRODUCT", referencedColumnName = "PRODUCT_ID")}, inverseJoinColumns = {
        	@JoinColumn(name = "STORE", referencedColumnName = "STORE_ID")})
        @ManyToMany
	private List<Store> storeList;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "productId")
	private List<ProductPurchase> productPurchaseList;

	public Product() {
	}

	public Product(Integer productId) {
		this.productId = productId;
	}

	public Product(Integer productId, String name, String code, int points, float price) {
		this.productId = productId;
		this.name = name;
		this.code = code;
		this.points = points;
		this.price = price;
	}

	public Integer getProductId() {
		return productId;
	}

	public void setProductId(Integer productId) {
		this.productId = productId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public int getPoints() {
		return points;
	}

	public void setPoints(int points) {
		this.points = points;
	}

	public float getPrice() {
		return price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	@XmlTransient
	public List<Store> getStoreList() {
		return storeList;
	}

	public void setStoreList(List<Store> storeList) {
		this.storeList = storeList;
	}

	@XmlTransient
	public List<ProductPurchase> getProductPurchaseList() {
		return productPurchaseList;
	}

	public void setProductPurchaseList(List<ProductPurchase> productPurchaseList) {
		this.productPurchaseList = productPurchaseList;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (productId != null ? productId.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are not set
		if (!(object instanceof Product)) {
			return false;
		}
		Product other = (Product) object;
		if ((this.productId == null && other.productId != null) || (this.productId != null && !this.productId.equals(other.productId))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "model.Product[ productId=" + productId + " ]";
	}
	
}
